﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GatherStrategy : IStrategy
{
    public GatherStrategy(Transform transform, float mNearbyRadium, float mForceWeight = 1) : base(transform, mNearbyRadium, mForceWeight) { }

    public override Vector3 GetForce()
    {       
        Vector3 center = Vector3.zero;
        Vector3 getherForce = Vector3.zero;

        
        foreach (GameObject n in mNearbyCrowList)
        {
            center += n.transform.position;
        }
        if (mNearbyCrowList.Count > 0)
        {
            //获取聚集的中心点
            center /= mNearbyCrowList.Count;


            Vector3 dirToCenter = center - this.mTransform.position;
            //越远聚集力越大
            getherForce += dirToCenter.normalized * dirToCenter.magnitude;
            getherForce *= mForceWeight;
        }

        return getherForce;
    }

    
}
